$(function () {
    getUserInfo()

})

let form = layui.form
//   获取用户信息
getUserInfo()
function getUserInfo() {
    axios({
        url: '/my/userinfo',
    }).then(res => {
        renderAvatar(res.data.data)
    })
}

// 渲染头像
function renderAvatar(user) {
    // console.log(user);
    let name = user.nickname || user.username
    let first = name[0].toUpperCase()
    $('.welcome').html(name)
    if (user.user_pic === null) {
        $('.layui-nav-img').hide()
        $('.userImg').show().html(first)
    } else {
        $('.layui-nav-img').show().attr('src', user.user_pic)
        $('.userImg').hide()
    }
}